package com.hsurosy.domain.activity.service.quota.policy.impl;

import com.hsurosy.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import com.hsurosy.domain.activity.model.valobj.OrderStateVO;
import com.hsurosy.domain.activity.repository.IActivityRepository;
import com.hsurosy.domain.activity.service.quota.policy.ITradePolicy;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Author Hsu琛君珩
 * @Date 2024-11-25 17:41
 * @Description 返利免支付交易策略
 * @Version: v1.0.0
 */
@Service("rebate_no_pay_trade")
public class RebateNoPayPolicy implements ITradePolicy {

    private final IActivityRepository activityRepository; // 活动仓储接口

    public RebateNoPayPolicy(IActivityRepository activityRepository) {
        this.activityRepository = activityRepository;
    }

    /**
     * 返利免支付交易逻辑的实现
     *
     * @param createQuotaOrderAggregate 创建订单的聚合对象，包含订单相关的所有数据
     */
    @Override
    public void trade(CreateQuotaOrderAggregate createQuotaOrderAggregate) {
        // 设置订单状态为已完成
        createQuotaOrderAggregate.setOrderState(OrderStateVO.completed);
        // 设置支付金额为 0
        createQuotaOrderAggregate.getActivityOrderEntity().setPayAmount(BigDecimal.ZERO);
        // 调用仓储接口保存免支付订单
        activityRepository.doSaveNoPayOrder(createQuotaOrderAggregate);
    }

}
